package com.xuecheng.api;

import com.xuecheng.base.exception.ValidationGroups;
import com.xuecheng.base.module.pageParams;
import com.xuecheng.base.module.pageResult;
import com.xuecheng.content.mapper.CourseBaseMapper;
import com.xuecheng.content.service.CourseBaseInfoService;
import com.xuecheng.module.dto.AddCourseDto;
import com.xuecheng.module.dto.CourseBaseInfoDto;
import com.xuecheng.module.dto.EditCourseDto;
import com.xuecheng.module.dto.QueryCourseParamsDto;
import com.xuecheng.module.po.CourseBase;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 星河一叶Ck
 * @date 2025/4/11
 */

@RestController
@Api(value = "课程信息编辑接口", tags = "课程信息编辑接口")
@RequiredArgsConstructor
public class CourseBaseInfoController {

    private final CourseBaseInfoService courseBaseInfoService;
    private final CourseBaseMapper courseBaseMapper;

    @ApiOperation("课程查询接口")
    @PostMapping("/course/list")
    public pageResult<CourseBase> list(pageParams pageParams, @RequestBody(required = false) QueryCourseParamsDto queryCourseParamsDto) {
        pageResult<CourseBase> courseBasepageResult = courseBaseInfoService.queryCourseBaseList(pageParams, queryCourseParamsDto);
        return courseBasepageResult;
    }

    @ApiOperation("添加课程基本信息接口")
    @PostMapping("/course")
    public CourseBaseInfoDto createCourseBase(@RequestBody @Validated({ValidationGroups.Insert.class})
                                                  AddCourseDto addCourseDto) {
        //机构id，由于认证系统没有上线暂时硬编码
        long companyId = 1232141425L;

        return courseBaseInfoService.createCourseBase(companyId, addCourseDto);
    }

    @ApiOperation("根据课程id查询课程")
    @GetMapping("/course/{id}")
    public CourseBaseInfoDto getCourseBaseInfo(@PathVariable Long id) {
        return courseBaseInfoService.getCourseBaseInfo(id);
    }

    @ApiOperation("根据课程id修改课程")
    @PutMapping("/course")
    public CourseBaseInfoDto updateCourseBase (@RequestBody @Validated({ValidationGroups.Update.class})
                                               EditCourseDto editCourseDto) {
        long companyId = 1232141425L;
        return courseBaseInfoService.updateCourseBase(companyId, editCourseDto);
    }
}
